package com.sanerzone.smscenter.gateway.ums.comm.smgp3;

import com.sanerzone.smscenter.gateway.ums.comm.PMessage;
import com.sanerzone.smscenter.gateway.ums.comm.PReader;
import com.sanerzone.smscenter.gateway.ums.comm.smgp3.message.*;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;

public class SMGP3Reader extends PReader {

    protected DataInputStream in;

    public SMGP3Reader(InputStream is) {
        in = new DataInputStream(is);
    }

    public PMessage read() throws IOException {
        PMessage result = null;
        int total_Length = in.readInt();//总长度
        int request_id = in.readInt(); //请求编号
        byte buf[] = new byte[total_Length - 8];
        in.readFully(buf);
        switch (request_id) {
            case RequestId3.LOGIN_RESP:
                result = new SMGP3LoginRespMessage(buf);
                break;
            case RequestId3.DELIVER:
                result = new SMGP3DeliverMessage(buf);
                break;
            case RequestId3.SUBMIT_RESP:
                result = new SMGP3SubmitRespMessage(buf);
                break;
            case RequestId3.FORWARD_RESP:
                result = new SMGP3ForwardRespMessage(buf);
                break;
            case RequestId3.QUERY_RESP:
                result = new SMGP3QueryRespMessage(buf);
                break;
            case RequestId3.ACTIVETEST_RESP:
                result = new SMGP3ActiveTestRespMessage(buf);
                break;
            case RequestId3.ACTIVETEST:
                result = new SMGP3ActiveTestMessage(buf);
                break;
            case RequestId3.EXIT:
                result = new SMGP3ExitMessage(buf);
                break;
            case RequestId3.EXIT_RESP:
                result = new SMGP3ExitRespMessage(buf);
                break;
            case RequestId3.QUERY_TE_ROUTE_RESP:
                result = new SMGP3MtRouteUpdateRespMessage(buf);
                break;
            case RequestId3.QUERY_SP_ROUTE_RESP:
                result = new SMGP3MoRouteUpdateRespMessage(buf);
                break;
        }
        return result;
    }
}
